home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 12 / 0 / DISK1205.ZIP / IDCUTIL / IDCUTIL.EXE / LETTER.ASM < prev    next >
Assembly Source File  |  1988-12-12  |  14KB  |  570 lines

  1.  
  2. ;================================================================
  3. ;Program    : LETTER.ASM                    |
  4. ;Author        : Gary Conway                    |
  5. ;Created    : 09.08.88                    |
  6. ;Update        : 12.11.88                    |
  7. ;Version    : 1.1                        |
  8. ;Notice        : Copyright 1988 Infinity Design Concepts    |
  9. ;          Inc. all rights reserved            |
  10. ;          1052 Parkway Drive                |
  11. ;          Louisville, Kentucky 40217            |
  12. ;          502-636-1234                    |
  13. ;================================================================
  14.  
  15. comment    |
  16.  
  17.     This source code is copyrighted material and may not be used
  18.     or reproduced for financial gain without the expressed written
  19.     consent of the author.
  20.  
  21.     |
  22.  
  23.  
  24. ; this program will print addresses on envelopes on the HP Laserjet series ][
  25. ; or brother HL-8 laser printers in landscape mode. The envelope will be
  26. ; inserted in the manual feed tray
  27. ; NOTE: The original source code is set for business envelopes, if you have
  28. ;       another size envelope that you wish to use, then you must change
  29. ;     this file and assemble it again. You will have to change the
  30. ;    TopMargin and LeftMargin variables.
  31.  
  32.  
  33. comment    |
  34.  
  35. ; ASSEMBLE with the following commands.
  36.  
  37.     masm letter;
  38.     link letter;
  39.     
  40.     |
  41.  
  42.  
  43. MajVer        Equ    "1"
  44. MinVer        Equ    "0"
  45.  
  46. ; define a macro for positioning the cursor on the screen
  47.  
  48. CURPOS    Macro    ROW,COL,PAGE    ;;macro to set cursor to desired screen pos.
  49.     Mov    DH,ROW
  50.     Mov    DL,COL
  51.     Mov    BH,PAGE
  52.     Mov    AH,2
  53.     Int    10H        ;; use BIOS routine (slow)
  54.     Endm
  55.  
  56.  
  57.  
  58. DSEG        Segment para public 'DATA'
  59.  
  60. CR        Equ    13        ; CR may now be used instead of 13
  61. LF        Equ    10        ; LF "    "  "   "    "       " 10
  62. ESCchar        Equ    27        ; ESC (ESCape) character
  63.  
  64.  
  65. ; define some variables for the built-in routines
  66.  
  67. CurShape    DW    ?        ; save shape of cursor when pgm. called
  68. Bksp_        DB    8,' ',8,0
  69. CONSBUFF    DB     100,00,100 DUP (' ')
  70.  
  71. Print_String    Label Byte
  72.  
  73. ;        DB    1Bh,0Dh,"H"    ; set to emulate HP laserjet+
  74.                     ;    (used ONLY on brother HL-8)
  75.         DB    1Bh,"&l3H"    ; set for envelopes
  76.         DB    1Bh,"&l1O"    ; set to landscape mode
  77.         DB    0        ; terminator
  78. Reset        DB    1Bh,"E",0    ; reset printer string
  79.  
  80. Control_C    DB    "Control-C to abort",cr,lf
  81.         DB    15 dup(" ")
  82.         DB    "If you find this program useful, please register!",0
  83.  
  84. SignOn        DB    "Ver. ",MajVer,".",MinVer," "
  85.         DB    "Copyright 1988, Infinity Design Concepts, Inc. all rights reserved",cr,lf,lf
  86.         DB    3 dup(" ")
  87.         DB    "This program will print envelopes on the"
  88.         DB    " HP LaserJet+ or compatible printer.",cr,lf
  89.         DB    9 dup(" ")
  90.         DB    "Note that the envelopes will be fed thru the manual tray",cr,lf
  91.         DB    20 dup(" ")
  92.         DB    "and printed in the LandScape mode."
  93.         DB    cr,lf,lf,lf,0
  94.  
  95. NotReady    DB    cr,lf,7,"Printer Not Ready... Hit ENTER.",7,cr,lf,0
  96. Blanks        DB    "                                       ",0
  97.  
  98. ; the prompts
  99.  
  100. Name1        DB    "Enter Name ..................: ",0
  101. Add1        DB    "Enter First Line of Address .: ",0
  102. Add2        DB    "Enter Second Line of Address : ",0
  103. City        DB    "Enter City ..................: ",0
  104. State        DB    "Enter State .................: ",0
  105. Zip        DB    "Enter Zip ...................: ",0
  106. Attn        DB    "Enter Attn of Name ..........: ",0
  107.  
  108. ; the following information is what is actually printed
  109.  
  110. Pr_name        DB    50 dup(0)
  111. Pr_add1        DB    50 dup(0)
  112. Pr_add2        DB    50 dup(0)
  113. Pr_City        DB    50 dup(0)
  114. Pr_State    DB    50 dup(0)
  115. Pr_Zip        DB    50 dup(0)
  116. Attn_Pr        DB    "Attn: "
  117. Pr_Attn        DB    50 dup(0)
  118.  
  119. DSEG        Ends
  120.  
  121.  
  122.  
  123. ; define the CODE segment
  124.  
  125. CSEG        Segment para public 'CODE'
  126.         ASSUME CS:CSEG,SS:ASTACK
  127.  
  128. ENTPT        Proc                ;Start of Code Execution
  129.         Mov    AX,DSEG         ; set up segment addresses
  130.         Mov    DS,AX            ; data seg.
  131.         Mov    ES,AX            ; extra seg.
  132.         ASSUME    DS:DSEG,ES:DSEG
  133.  
  134.         Call    SaveCursor        ; save cursor shape
  135.         Call    Clrsc            ; clear the screen
  136.         Call    Curoff            ; turn cursor off
  137.  
  138.         CurPos    1,0,0
  139.         Lea    SI,SignOn
  140.         Call    Ilprt            ; print signon message
  141.  
  142.         CurPos    18,31,0            ; put cursor at 18,31
  143.         Lea    SI,Control_C
  144.         Call    Ilprt            ; print abort msg.
  145.         
  146.         CurPos    9,0,0            ; put cursor at 9,0
  147.         Call    Curon            ; turn cursor back on
  148. ; get name
  149.         Lea    SI,Name1
  150.         Call    Ilprt            ; print name prompt
  151.         Call    Rdcons            ; get string from user
  152.         Lea    SI,Consbuff +2
  153.         Lea    DI,Pr_name        ; destination for printing
  154.         Call    Insert            ; put user string there
  155.         Call    Crlf            ; send crlf to screen
  156.  
  157. ; get address line 1
  158.  
  159.         Lea    SI,Add1
  160.         Call    Ilprt            ; print addr.line 1 prompt
  161.         Call    Rdcons            ; get string from user
  162.         Lea    SI,Consbuff +2
  163.         Lea    DI,Pr_add1
  164.         Call    Insert            ; store it
  165.         Call    Crlf
  166.  
  167. ; get address line 2
  168.  
  169.         Lea    SI,Add2
  170.         Call    Ilprt
  171.         Call    Rdcons
  172.         Lea    SI,Consbuff +2
  173.         Lea    DI,Pr_add2
  174.         Call    Insert
  175.         Call    Crlf
  176.  
  177. ; get city
  178.         Lea    SI,City
  179.         Call    Ilprt
  180.         Call    Rdcons
  181.         Lea    SI,Consbuff +2
  182.         Lea    DI,Pr_city
  183.         Call    Insert
  184.         Call    Crlf
  185. ; get state
  186.  
  187.         Lea    SI,State
  188.         Call    Ilprt
  189.         Call    Rdcons
  190.         Lea    SI,Consbuff +2
  191.         Lea    DI,Pr_state
  192.         Call    Insert
  193.         Call    Crlf
  194. ; get zip
  195.         Lea    SI,Zip
  196.         Call    Ilprt
  197.         Call    Rdcons
  198.         Lea    SI,Consbuff +2
  199.         Lea    DI,Pr_zip
  200.         Call    Insert
  201.         Call    Crlf
  202. ; get attn of
  203.         Lea    SI,Attn
  204.         Call    Ilprt
  205.         Call    Rdcons
  206.         Lea    SI,Consbuff +2
  207.         Lea    DI,Pr_attn
  208.         Call    Insert
  209.  
  210. Test_Ptr:    Mov    AH,2
  211.         Xor    DX,DX
  212.         Int    17h        ; read printer status
  213.         Test    AH,01001001b    ; bit 7 = busy
  214.                     ; bit 5 = out of paper
  215.                     ; bit 3 = I/O error
  216.                     ; bit 0 = time out
  217.         Jz    Ptr_Ready
  218.         CurPos    20,0,0
  219.         Lea    SI,NotReady
  220.         Call    Ilprt
  221.         Mov    AH,8
  222.         Int    21h        ; wait for character and test again
  223.         Jmp    Short Test_Ptr
  224.  
  225. Ptr_Ready:    CurPos    20,0,0
  226.         Lea    SI,Blanks
  227.         Call    Ilprt            ; remove error msg if there
  228.  
  229.         Lea    SI,Print_String
  230.         Call    Print            ; set printer to proper mode
  231.         Call    Print_CRs        ; print 20 crlf's
  232.         Call    Print_Env        ; print the envelope
  233.         Call    Pcrlf            ; carriage return linefeed
  234.         Mov    AL,12
  235.         Call    Prchar            ; send forfeed
  236.         Lea    SI,Reset
  237.         Call    Print            ; reset printer to control
  238.                         ; panel defaults
  239. Exit:        CurPos    20,0,0            ; put cursor at 20,0
  240.         Call    Curon            ; turn cursor on
  241.         Mov    AX,4C00h        ; return to DOS
  242.         Int    21h
  243.  
  244. ;--------------------------------------------------------------------------
  245. ;            SUPPORT ROUTINES
  246. ;--------------------------------------------------------------------------
  247.  
  248.  
  249.  
  250. ;------------------------------------------------------------------
  251. ; THIS ROUTINE DETERMINES WHERE THE TEXT ON THE ENVELOPE WILL START
  252. ; AS MEASURED FROM THE TOP OF THE ENVELOPE
  253. ; If you wish to change this distance, change TopMargin below to
  254. ; whatever works for you
  255. ; send 20 carriage return and linefeeds to the printer
  256. ;------------------------------------------------------------------
  257.  
  258. TopMargin    Equ    20
  259.  
  260. Print_CRs    Proc
  261.         Mov    CX,TopMargin    ; send this many crlf's
  262. Pr_1:        Push    CX
  263.         Call    Pcrlf
  264.         Pop    CX
  265.     Loop    Pr_1
  266.         Ret
  267. Print_CRs    Endp
  268.  
  269. ;------------------------------------------------------------------
  270. ; THIS ROUTINE DETERMINES WHERE THE TEXT ON THE ENVELOPE WILL START
  271. ; AS MEASURED FROM THE LEFT MARGIN. If you wish to change this
  272. ; distance, change LeftMargin below.
  273. ; send 37 spaces to the printer
  274. ;-------------------------------------------------------------------
  275.  
  276. LeftMargin    Equ    37            ; left margin
  277.  
  278. Print_Space    Proc
  279.         Mov    CX,LeftMargin        ; this many spaces
  280. Pr_Sp:        Push    CX            ; save it
  281.         Mov    AL," "
  282.         Call    Prchar            ; send space to printer
  283.         Pop    CX
  284.     Loop    Pr_Sp                ; loop till done
  285.         Ret
  286. Print_Space    Endp
  287.  
  288.  
  289. ;---------------------------------------
  290. ; this procedure will print the envelope
  291. ;---------------------------------------
  292.  
  293. Print_Env    Proc
  294.         Call    Print_Space        ; print 37 spaces
  295.         Lea    SI,PR_name        ; point to name string
  296.         Cmp    Byte Ptr[SI],0        ; empty ?
  297.         Je    Empt_1            ; yup, skip it
  298.         Call    Print            ; else, print the string
  299.         Call    Pcrlf            ; and a crlf
  300.         Call    Print_Space        ; print 37 spaces
  301.  
  302. ; print address line 1
  303.  
  304. Empt_1:        Lea    SI,Pr_add1        ; point to addr line 1 string
  305.         Cmp    Byte Ptr [SI],0        ; empty ?
  306.         Je    Empt_2            ; yup, skip it
  307.         Call    Print            ; else print it
  308.         Call    Pcrlf            ; and a crlf
  309.         Call    Print_Space        ; print 37 spaces
  310.  
  311. ; print address line 2, if not empty
  312.  
  313. Empt_2:        Lea    SI,Pr_add2        ; point to addr line 2 string
  314.         Cmp    byte Ptr [SI],0        ; string empty ?
  315.         Je    Empt_3            ; yup, skip it
  316.         Call    Print            ; else, print it
  317.         Call    Pcrlf            ; and a crlf
  318.         Call    Print_Space        ; print 37 spaces
  319.  
  320. ; print city,state, zip
  321.  
  322. Empt_3:        Lea    SI,Pr_city        ; point to city string
  323.         Call    Print            ; print it
  324.         Mov    AL,","
  325.         Call    Prchar            ; and a comma
  326.         Mov    AL," "
  327.         Call    Prchar            ; and a space
  328.         Lea    SI,Pr_State
  329.         Call    Print            ; print state
  330.         Mov    AL," "
  331.         Call    Prchar            ; and a space
  332.         Lea    SI,Pr_Zip
  333.         Call    Print            ; print zip code
  334.         Call    Pcrlf
  335.  
  336. ; print attn if not empty
  337.  
  338.         Cmp    Byte Ptr [Pr_Attn],0    ; user string empty ?
  339.         Je    Empt_4            ; yup, skip it
  340.         Call    Print_Space        ; print 37 spaces
  341.         Lea    SI,Attn_Pr        ; point to "Attn:" string
  342.         Call    Print            ; and print it
  343. Empt_4:        Ret        
  344. Print_Env    Endp
  345.  
  346.  
  347.  
  348. ;-----------------------------------------------
  349. ; send a carriage return and linefeed to printer
  350. ;-----------------------------------------------
  351.  
  352. Pcrlf        Proc
  353.         Mov    AL,CR
  354.         Call    Prchar
  355.         Mov    AL,LF
  356.         Call    Prchar
  357.         Ret
  358. Pcrlf        Endp
  359.  
  360. ;-----------------------------------
  361. ; send ASCIZ string in SI to printer
  362. ;-----------------------------------
  363.  
  364. Print        Proc
  365.         Lodsb            ; get character
  366.         Or    AL,AL        ; is it zero ?
  367.         Je    Pr_Dne        ; yup, then done
  368.         Call    Prchar        ; else, print the char
  369.         Jmp    Short Print    ; keep going till zero
  370. Pr_Dne:        Ret
  371. Print        Endp
  372.  
  373. ;---------------------------
  374. ; send char in AL to printer
  375. ;---------------------------
  376.  
  377. Prchar        Proc
  378.         Push    SI
  379.         Mov    DL,AL
  380.         Mov    AH,5
  381.         Int    21h        ; send char in DL to printer
  382.         Pop    SI
  383.         Ret
  384. Prchar        Endp
  385.  
  386. ;---------------------------------------------------------------------
  387. ; this procedure will move the string from SI to DI and stop with the
  388. ; CR character and replace it with a zero
  389. ;---------------------------------------------------------------------
  390.  
  391. Insert        Proc
  392.         Lodsb            ; get source character
  393.         Or    AL,AL        ; terminator ?
  394.         Jz    All_Done    ; then quit
  395.         Stosb            ; else, store it
  396.         Jmp    Short Insert    ; do em all
  397. All_Done:    Ret
  398. Insert        Endp
  399.  
  400.  
  401. ;-----------------
  402. ; clear the screen
  403. ;-----------------
  404.  
  405. Clrsc        Proc
  406.         Mov    AX,0600h    ; scroll function
  407.         Mov    BH,15        ; clear attribute
  408.         Xor    CX,CX        ; upper left corner
  409.         Mov    DX,184Fh    ; lower right corner
  410.         Int    10h        ; BIOS clear screen
  411.         Ret
  412. Clrsc        Endp
  413.  
  414. ;--------------------------------------------------
  415. ; send a carriage return and linefeed to the screen
  416. ;--------------------------------------------------
  417.  
  418. Crlf        Proc
  419.         Mov    AL,CR
  420.         Call    Pchar
  421.         Mov    AL,LF
  422.         Call    Pchar
  423.         Ret
  424. Crlf        Endp
  425.  
  426.  
  427. ;--------------------------------------------------
  428. ; send an ASCIIZ string to the screen,   SI is pntr
  429. ;--------------------------------------------------
  430.  
  431.  
  432. Ilprt        Proc            ; on exit SI points to 0 terminator
  433.         Lodsb            ; get character
  434.         Or    AL,AL        ; is it terminator ?
  435.         Jz    ILK1        ; yup, then done
  436.         Call    Pchar        ; else print char on screen
  437.         Jmp    Short Ilprt    ; do em all
  438. ILK1:        Ret
  439. Ilprt        Endp
  440.  
  441. ;---------------------------
  442. ; print char in AL on screen
  443. ;---------------------------
  444.  
  445. Pchar        Proc
  446.         Push    CX        ; save some regs
  447.         Push    SI
  448.         Push    DI
  449.         Mov    AH,2
  450.         Mov    DL,AL        ; move char into DL
  451.         Int    21H        ; put on screen
  452.         Pop    DI
  453.         Pop    SI
  454.         Pop    CX
  455.         Ret
  456. Pchar        Endp
  457.  
  458. ;--------------------
  459. ; turn the cursor off
  460. ;--------------------
  461.  
  462. Curoff        Proc
  463.         Push    AX
  464.         Mov    CX,2000H
  465.         Mov    AH,1
  466.         Int    10h
  467.         Pop    AX
  468.         Ret
  469. Curoff        Endp
  470.  
  471. ;------------------------
  472. ; turn the cursor back on
  473. ;------------------------
  474.  
  475. Curon        Proc
  476.         Push    AX
  477.         Mov    CX,[CurShape]    ; retrieve cursor shape
  478.         Mov    AH,1        ; set cursor mode
  479.         Int    10h
  480.         Pop    AX
  481.         Ret
  482. Curon        Endp
  483.  
  484. ;----------------------------------------------------------------
  485. ; save the current shape of the cursor so when we turn it back on
  486. ; it is still the same. Note that this routine should really be
  487. ; called before turning the cursor OFF the first time and should
  488. ; definitely be called before calling CURON
  489. ;----------------------------------------------------------------
  490.  
  491. SaveCursor    Proc            ; get cursor start and stop lines
  492.         Push    ES        ; from 0040:0060 and save for
  493.         Mov    AX,40h        ; cursor on routine
  494.         Mov    ES,AX
  495.         Mov    CX,ES:[60H]
  496.         Pop    ES
  497.         Mov    [CurShape],CX
  498.         Ret
  499. SaveCursor    Endp
  500.  
  501.  
  502.  
  503.  
  504. ;---------------------------------------
  505. ; read string from console into CONSBUFF
  506. ;---------------------------------------
  507.  
  508.  
  509. RDcons        Proc
  510.         Call    Conbfset    ; blank the buffer
  511.         Lea    DI,Consbuff +2    ; dest buffer
  512.         Xor    CX,CX        ; char count
  513. GetChr:        Xor    AH,AH        ; BIOS wait for char
  514.         Int    16h
  515.         Or    AH,AH
  516.         Jz    GetChr        ; no extended codes
  517.         Cmp    AL,3        ; ^C
  518.         Jne    Not_C
  519.         Jmp    Exit        ; user aborted
  520. Not_C:        Cmp    AL,13
  521.         Je    EndInput    ; CR allowed (end)
  522.         Cmp    AL,8
  523.         Je    BkSpace        ; backspace allowed (edit)
  524.         Cmp    AL,' '
  525.         Jb    GetChr        ; no other control codes allowed
  526.         Cmp    AL,7Bh
  527.         Jae    GetChr        ; no graphics either
  528. PutChr:        Call    Pchar
  529.         Stosb            ; put char in buffer
  530.         Inc    CX        ; increment out count
  531.         Cmp    CX,80        ; at max ?
  532.         Jb    GetChr        ; if < 80, then get more
  533.         Jmp    Short EndInput
  534.  
  535. BkSpace:    Cmp    CX,0
  536.         Je    GetChr        ; no chars to delete
  537.         Push    DI
  538.         Push    CX
  539.         Lea    SI,Bksp_    ; print 8,' ',8
  540.         Call    Ilprt
  541.         Pop    CX
  542.         Pop    DI
  543.         Dec    DI        ; decr buffer ptr
  544.         Dec    CX        ; decr num chars entered
  545.         Jmp    GetChr
  546.  
  547. EndINput:    Xor    AL,AL
  548.         Stosb            ; add another delimiter
  549.         Mov    Consbuff +1,CL    ; install num chars entered
  550.         Ret
  551.  
  552. Conbfset    Proc                ; set console buffer
  553.         Lea     DI,Consbuff+2
  554.         Mov    CX,80            ; pad 80 blanks
  555.         Mov    AL,' '
  556.     Rep    Stosb                ; store all blanks
  557.         Ret
  558. Conbfset    Endp
  559.  
  560. RDcons        Endp
  561.  
  562.  
  563. ENTPT        Endp
  564. CSEG        Ends
  565.  
  566. ASTACK        Segment para stack 'STACK'
  567.         DB    25 DUP("HAYSTACK   ")      ; stack area
  568. ASTACK        Ends
  569.         End    ENTPT
  570.